#include <iostream>
using namespace std;

typedef struct{
 int num;
 string name;
 int grade;
}ElemType;
typedef struct{
 ElemType data[66];
 int length;
}student;

int main(){
 student *L1,*L2,*L3;
 L1 = new student;
 L2 = new student;
 L3 = new student;
 for(int i = 0; i < 12;i++){
  cin >> L1->data[i].num >> L1->data[i].name
   >> L1->data[i].grade;
  L1->length = 12;
 }
 for(int i = 0; i < 13; i++){
  cin >> L2->data[i].num >> L2->data[i].name
   >> L2->data[i].grade;
  L2->length = 13;
 }
 int i=0,j=0,k=0;
 while(i < L1->length && j < L2->length){
  if(L1->data[i].grade >= L2->data[j].grade){
   L3->data[k] = L1->data[i];
   k++;i++;
  }
  else{
   L3->data[k] = L2->data[j];
   j++;k++;
  }
 }
 while(i<L1->length){
  L3->data[k] = L1->data[i];
  i++;k++;
 }
 while(j<L2->length){
  L3->data[k] = L2->data[j];
  j++;k++;
 }
 L3->length = k;
 
 for(int i = 0; i < k; i++){
  cout << L3->data[i].num << " " 
   << L3->data[i].name << " "
   << L3->data[i].grade <<endl;
 }
} 
